package 多线程.AQS.CyclicBarriereTest;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo2 {
    public static void main(String[] args) throws InterruptedException {
        CyclicBarrier cyclicBarrier=new CyclicBarrier(2);
        new Thread(()->{
            try {
                cyclicBarrier.await();
                cyclicBarrier.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                throw new RuntimeException(e);
            }
        }).start();
        Thread.sleep(100);
        //当前正在屏障点等待的线程
        System.out.println(cyclicBarrier.getNumberWaiting());//1
        System.out.println(cyclicBarrier.isBroken());//false
        //可以看到，**单个**线程无法两次减少屏障的计数，第二个await是无用的，
        // 还有就是broken为false，说明还在本Generation中。
    }
}